package jp.co.cos.ittrick.channel.controller.client;

import jp.co.cos.ittrick.channel.meta.TableModelMeta;
import jp.co.cos.ittrick.channel.model.TableModel;
import jp.co.cos.ittrick.channel.service.TableService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class GetTableController extends Controller {

    private TableService tableService;

    public GetTableController() {
        tableService = new TableService();
    }

    @Override
    protected Navigation run() throws Exception {

        // リクエストパラメータ
        String table = asString("table");

        TableModel tableModel = tableService.getTableByKey(Integer.valueOf(table));

        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json");
        response.getWriter().println(TableModelMeta.get().modelToJson(tableModel));
        response.flushBuffer();

        return null;
    }

}
